package com.yyg.usecase.springbootwebdemo.service.validator;

import lombok.Data;

import javax.validation.Valid;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;

@Data
public class UserRequest {
    @NotBlank(message = "userId不能为空", groups = {UserUpdateGroup.class})
    private String userId;
    @NotBlank(message = "userName不能为空", groups = {UserCreateGroup.class})
    private String userName;
    @NotBlank(message = "mobile不能为空", groups = {UserCreateGroup.class})
    @Pattern(regexp = "^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\\d{8}$", message = "电话号码格式错误")
    private String mobile;
    @NotNull(message = "userDetail不能为空", groups = {UserCreateGroup.class})
    @Valid
    private UserDetail userDetail;
}
@Data
class UserDetail {
    @Min(message = "年龄不能小于0",value = 0, groups = {UserCreateGroup.class, UserUpdateGroup.class})
    @Max(message = "年龄不能大于200",value = 100, groups = {UserCreateGroup.class, UserUpdateGroup.class})
    Integer age;
    String address;
}
@interface UserUpdateGroup {
}
@interface UserCreateGroup {
}